﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace EShop.Common
{
    public class INI
    {
        private static string filePath = Environment.CurrentDirectory + "\\Setting.ini";

        public static string FilePath
        {
            get { return INI.filePath; }
        }
        [DllImport("kernel32.dll")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        [DllImport("kernel32.dll")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

        public static void Write(string section, string key, string val)
        {
            WritePrivateProfileString(section, key, val, filePath);
        }

        public static object Read(string section, string key)
        {
            StringBuilder sb = new StringBuilder(255);
            GetPrivateProfileString(section, key, "0", sb, 255, filePath);
            return (object)sb;
        }
    }
}
